<?php
/**
 * 情報誌No.検索用関数<br />
 *
 * @package apamanshop
 * @author　SS木下
 * @copyright　
 */
class Search_Model_Seljyohoshisearch extends Apm_Model_Base {

	/**
	* 情報誌データ取得
	*/
	public function getJyohoshiData($params)
    {
        $db_params = array();
        $sql = $this->generateJyohoshiSql($params, $db_params);
        return $this->dbGetList($sql, $db_params);
    }

   /**
	* 情報誌データを表示用に変換
	*
	* @access	public
	* @param	array ※参照渡し
	* @return	void
	*/
	public function convertJyohoshiData(&$data)
	{
		$data['Mapping'] = array();

		foreach ($data['seljyohoshi'] as $jyohoshiData)
		{

		}

	}

    /**
     * 情報誌データ検索用SQL文の取得
     *
     * 情報誌一覧データ検索用SQL文の取得を行う
     * @access	public
     * @param	array
     * @param	array
     * @return	string 市区町村データ検索用SQL
     */
    public function generateJyohoshiSql($params,&$db_params)
    {


    	$db_params['strHan'] = substr($params['SchNo'],0,2);
     	$db_params['strRoomNo'] = substr($params['SchNo'],2,5);

		$sql = "   	SELECT ";
		$sql .= "		 		T03_HEYA_CD as HEYA_CD ";
		$sql .= "		  FROM ";
		$sql .= "		 		T03WEB_HEYA, T77ROOM_SEARCHNO ";
		$sql .= "	  WHERE ";
		$sql .= "		 		T77_HAN_CD = :strHan AND T77_ROOM_SEARCH_NO = :strRoomNo ";
		$sql .= "		 		AND T03_KASHIDASHI_KUBUN = T77_KASHIDASHI_KUBUN ";
		$sql .= "		 		AND (T03_ORIGINAL_HEYA_CD01 = T77_ORIGNAL_TATEMONO_CD01||'-'||SUBSTR(T77_ORIGNAL_HEYA_BANGO, 1, LENGTH(T03_HEYA_BANGOU)) ";
		$sql .= "		 		OR T03_ORIGINAL_HEYA_CD02 = T77_ORIGNAL_TATEMONO_CD01||'-'||SUBSTR(T77_ORIGNAL_HEYA_BANGO, 1, LENGTH(T03_HEYA_BANGOU)) ";
		$sql .= "		 		OR T03_ORIGINAL_HEYA_CD01 = SUBSTR(T77_ORIGNAL_HEYA_CD, 1,LENGTH(T03_ORIGINAL_HEYA_CD01))) ";
		$sql .= "		 		AND T03_TENPO_CD = T77_TENPO_CD ";

        return $sql;
    }


   /**
	* 都道府県・市区町村コードWhere句作成
	*
	* @access	public
	* @param	string
	* @param	string
	* @param	array
	* @param	string
	* @return	void
	*/

	private function createWhere($colums,$params)
	{
		// コード数分ループ
		for($i=0;$i<count($params);$i++){

			if($i == 0){
				$sql = " ( ".$colums." = '".$params[$i]."'";
			}else{
				$sql.= " OR ".$colums." = '".$params[$i]."' ";
			}
		}

		$sql .= ")";

		return $sql;
	}
}

?>